<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="packaging.*" %>
<%@ page import="java.sql.*" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <base href="<%=basePath%>">   
    <title>My JSP 'buy.jsp' starting page</title>  
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/indexcss.css">
		<script type="text/javascript">
	function check(input,id){				
				var num = input.value ;	
				//isNaN判断num是否为数值，不是返回true，是返回false
				//indexOf('.')查找字符中是否带有‘.’符号，带有就返回‘.’所在的位置，没带有返回-1
				//如2.2这种也算是数值，但我们数量应该是整型数据，因此也不允许不是整型的数据输入
				if(isNaN(num) || num.indexOf('.')!=-1){
					alert("请不要输入非法字符，数量必须是整型数值");
					input.value = "" ;
					input.focus();
					return ;
				}else if(num==""){
					alert("请输入要修改的数量");
					input.focus();
					return ;
				}
				var url = "update.jsp?id="+id+"&num="+num ;
				document.carform.action = url ;
				document.carform.submit();
			}
		</script>

  </head>
  
  <body>

		<%
			Map<String, CartBean> car = (Map<String, CartBean>) session.getAttribute("car");		
			int numb = 0;
			if (car != null) {
				for (String key : car.keySet()) {
					CartBean cb = car.get(key);
					int num = cb.getNum();
					numb = numb + num;

				}

			}
		%>
		<%
			session.setAttribute("numb", numb);
		%>
		<div id="s2">
			<table width="950px" border="0">
				<tr>
					<td width="172" rowspan="2">
						<img src="img/logo.png" width="159" height="85px" />
					</td>
					<td width="395" height="76">
						<p>
							您好!
							<%
							if (session.getAttribute("USER") == null) {
						%>
							<a href="lp.jsp">请登录</a>
												<%
								} else {
							%>

					<a href="buy.jsp">  <%
  	out.print(session.getAttribute("USER"));}
  %>
 	 <%
 	 	if (session.getAttribute("numb") == null) {
 	 			out.print("");
 	 		} else {
 	 			out.print("你的购物车共有" + session.getAttribute("numb") + "件商品");

 	 		}

 	 	
 	 %>
					</a>
						</p>
						<p>
							<span style="color: #FF9966; font-size: 15px"> </span><span
								style="color: #FF9966; font-size: 15px"> 全场购物免配送费! </span>
						</p>
					</td>
					<td width="369" style="color: #FF9966; font-size: 15px">
						<form id="form1" name="form1" method="post" action="check.jsp">

							<input type="text" name="con" id="" size="18" />


							<input type="submit" name="button" id="button" value="搜索"
								style="background: #F6F6F6;" />

						</form>
					</td>
				</tr>
				<tr>
					<td height="15" style="color: #004B91; font-weight: bold">
						我的START SHOES | 礼品卡
					</td>
					<td style="color: #004B91;">
						我的帐户 | 新手上路 | 帮助
					</td>
				</tr>
			</table>
			<ul style="background-image: url(img/title.jpg)">
				<li><a href="index.jsp">
					首页
					</a>
				</li>
				<li>
					品牌馆
				</li>
				<li>
					男鞋
				</li>
				<li>
					女鞋
				</li>

			</ul>
		</div>
  <div style="padding-top:0px; margin-top:0px;border: 1px #CCCCCC solid; width:940;">
   <form name="carform" action="doUpdateCar.jsp"  method="post">
   <table  style="border:solid 1px #CCCCCC" align="center" width="940">
		<tr>
			<td colspan="6" align="center">购物车商品列表</td>
		</tr>
		<tr>
			<th width="100">商品图片</th>
			<th width="300">商品名称</th>
			<th width="100">单价</th>
			<th width="100">数量</th>
			<th width="150">金额</th>
			<th width="100">操作</th>
		</tr>
   <%
    car = (Map<String, CartBean>) session.getAttribute("car");
   			
   	double total = 0;

   	if (car != null) {
   		for (String key : car.keySet()) {
   			CartBean cb = car.get(key);
   			bean p = cb.getBen();
   			int num = cb.getNum();
   			total = total + num * p.getImgnewprice();
   			numb = numb + num;
   %>
		<tr >
			<td align="center"><img src="<%=p.getImgimg()%>"  width="100px"/></td>
			<td align="center" style=" color:#3333FF;font-size:14px;font-weight:200"><%=p.getImgname()%></td>
			<td align="center"><%=p.getImgnewprice()%></td>
			<td align="center"><input name="num" value="<%=num%>" size="5" onblur="check(this,<%=p.getImgid()%>)"/></td>
			<td align="center">¥<%=num * p.getImgnewprice()%></td>
			<td align="center"><a href="doDelBuy.jsp?id=<%=p.getImgid()%>" onclick="return del()">删除</a></td>
		</tr>			
		<%
						}
						}
					%>
		
		  
		
		<tr>
			<td colspan="1" align="center"><a href="index.jsp">继续购买</a></td>
			<td colspan="2" align="center"><a href="accounts.jsp">去结帐</a></td>
			<td colspan="2" align="center"><font color="red">总价格：¥<%=total%></font></td>
						
		</tr>
	</table>	
	</form>
	</div>
  </body>
</html>
